﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Mojito.Data.Initialization;
using Mojito.Entity;
using Mojito.Service;
using Sohobloo.SoCommon.CommonExtension;
using Sohobloo.SoCommon.Log;
using Sohobloo.SoMcCoffee.Mef;
using Mojito.Common;

namespace Mojito.TestConsole
{
    [Export]
    internal class Program : ILoggable
    {
        [Import]
        public ILogger Logger { get; set; }

        private static void Main(string[] args)
        {
            MefProgramConfig.RegisterSolver<Program>();
            var program = MefProgramConfig.GetExportedProgram<Program>();
            program.Run();
            Console.WriteLine("---------Test End---------");
            Console.ReadKey();
        }

        void Run()
        {
            LogInitializer.Initialize(enableTraceSql:true);
            DbInitializer.Initialize(DbInitializer.DbInitializMode.Migrate);


            TestObfuscate();
        }

        [Import]
        public ITableService TableService { get; set; }
        [Import]
        public IDishCategoryService DishCategoryService { get; set; }
        [Import]
        public IDishService DishService { get; set; }
        [Import]
        public IShopConfig ShopConfig { get; set; }
        [Import]
        public IOrderService OrderService { get; set; }

        void TestTable()
        {
            try
            {
                //table2.MinConsumptionType = MinConsumptionType.PerCapital;
                //table2.MinConsumptionAmount = 50d;
                //TableService.Update(table2);

                //TableService.SortAfter(table3, table1.Id);

                //TableService.Delete(table1.Id);
            }
            catch(Exception ex)
            {
                this.LogError(ex);
                Console.WriteLine("Error!");
            }
        }

        void TestDish()
        {
            var dc1 = DishCategoryService.AddDishCategory("TestCategory1").AppendData as DishCategory;
            var d1 = DishService.AddDish(dc1.Id, "TestDish1", 50, DishTagType.New).AppendData as Dish;
            Console.WriteLine(d1.Category.CategoryName);
        }

        void TestShopConfig()
        {
            ShopConfig.ConfuseOrderNumber = true;
        }

        void TestOrderService()
        {
            OrderService.GetCurrentOrderList();
        }

        void TestObfuscate()
        {
            Console.WriteLine("201409040001 | " + OrderNumberObfuscator.Obfuscate("201409040001"));
            Console.WriteLine("201409040001 | " + OrderNumberObfuscator.Obfuscate("201409040001"));
            Console.WriteLine("201409040001 | " + OrderNumberObfuscator.Obfuscate("201409040001"));
            Console.WriteLine("201409040002 | " + OrderNumberObfuscator.Obfuscate("201409040002"));
            Console.WriteLine("201409040003 | " + OrderNumberObfuscator.Obfuscate("201409040003"));
            Console.WriteLine("201409040004 | " + OrderNumberObfuscator.Obfuscate("201409040004"));
            Console.WriteLine("201409040005 | " + OrderNumberObfuscator.Obfuscate("201409040005"));
            Console.WriteLine("201409050001 | " + OrderNumberObfuscator.Obfuscate("201409050001"));
            Console.WriteLine("201409060001 | " + OrderNumberObfuscator.Obfuscate("201409060001"));
            Console.WriteLine("201410040001 | " + OrderNumberObfuscator.Obfuscate("201410040001"));
            Console.WriteLine("201509040001 | " + OrderNumberObfuscator.Obfuscate("201509040001"));
        }
    }
}
